<!-- 我的服务商 -->
<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb-8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleOpen()"
          v-hasPermi="['facilitator:myFacilitator:add']"
          >邀请服务商合作</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-view"
          size="mini"
          @click="goCooperationRecord"
          v-hasPermi="['facilitator:myFacilitator:edit']"
          >合作申请管理</el-button
        >
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="dataList">
      <el-table-column label="服务商名称" align="center" prop="companyName" />
      <el-table-column label="合作模式" align="center" prop="cooperateType">
        <!-- 合作模式: 0无 1统一定价返佣 2采购价结算 -->
        <template slot-scope="{row}">
          <div>{{ row.cooperateType === 2 ? '采购价结算' : (row.cooperateType === 1 ? '统一定价返佣' : '无') }}</div>
        </template>
      </el-table-column>
      <el-table-column label="返利比例" align="center" prop="commissionRatio">
        <template slot-scope="{row}">
          <div>{{ row.commissionRatio }}%</div>
        </template>
      </el-table-column>
      <el-table-column label="控价状态" align="center" prop="priceControl">
        <template slot-scope="{row}">
          <div>{{ row.priceControl === 1 ? '控价' : '不控价' }}</div>
        </template>
      </el-table-column>
      <el-table-column label="服务商地址" align="center" prop="companyAddress" />
      <el-table-column label="服务商联系人" align="center" prop="adminname" />
      <el-table-column label="联系人电话" align="center" prop="mobile" />
      <el-table-column label="合作时间" align="center" prop="createTime" />
      <el-table-column

        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="120px"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button v-hasPermi="['facilitator:myFacilitator:delete']" size="mini" type="text" @click="handleDelete(scope.row)"
            >解绑服务商</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <EditCooperation ref="EditCooperation" @refresh="getList" />
  </div>
</template>
<script>
import { getCooperateList, deleteApplyCooperate } from "@/api/facilitator";
import EditCooperation from "./editCooperation"

export default {
  name: "MyFacilitator",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      // 总条数
      total: 0,
      dataList: [],
    };
  },
  components: {
    EditCooperation
  },
  created() {
    this.getList();
  },
  activated() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      getCooperateList(this.queryParams)
        .then((response) => {
          this.dataList = response.rows;
          this.total = response.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    handleOpen() {
      this.$refs.EditCooperation.openModal()
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.$modal
        .confirm(`是否确认要解绑(${row.companyName})？解绑后，您负责的医疗机构将无法再使用该服务商提供的产品或服务。`)
        .then(function () {
          return deleteApplyCooperate({ id: row.id });
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("成功解绑");
        })
        .catch(() => {});
    },
    goCooperationRecord() {
      this.$router.push({path: '/facilitator/cooperationRecord/index'})
    }
  }
};
</script>
<style lang="scss" scoped></style>
